//
//  ILButton.m
//  PlayCatchGame
//
//  Created by 流言 on 2018/3/1.
//  Copyright © 2018年 清正. All rights reserved.
//

#import "ILButton.h"


@interface ILButton() {
    UIView *_lineView;
}

@end

@implementation ILButton

- (instancetype)initWithFrame:(CGRect)frame {
    self =[super initWithFrame:frame];
    if (self) {
        self.text_image_space =2.0;
        [self creactView];
    }
    return self;
}

- (void)creactView {
    _lineView =[[UIView alloc]init];
    _lineView.backgroundColor =[UIColor clearColor];
    [self addSubview:_lineView];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.centerY.mas_equalTo(self.mas_centerY).offset(self.textImage_view_center);
        make.width.mas_equalTo(self.text_image_space);
        make.height.mas_equalTo(self.text_image_space);
    }];
    
    self.imageView =[[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:self.imageView];
    
    self.label =[[UILabel alloc] initWithFrame:CGRectZero];
    self.label.textAlignment =NSTextAlignmentCenter;
    self.label.adjustsFontSizeToFitWidth =YES;
    self.label.textColor =[UIColor grayColor];
    if ([UIScreen mainScreen].bounds.size.width ==320.0) {
        self.label.font =[UIFont systemFontOfSize:15];
    }
    [self addSubview:self.label];
    
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.bottom.mas_equalTo(_lineView.mas_top).offset(0);
    }];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lineView.mas_bottom).offset(0);
        make.left.mas_equalTo(self.mas_left).offset(0);
        make.right.mas_equalTo(self.mas_right).offset(0);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-5);
    }];
}

- (void)setText_image_space:(CGFloat)text_image_space {
    if (_text_image_space != text_image_space) {
        _text_image_space =text_image_space;
        
        [self updateConstraints_lineView];
    }
}

- (void)setTextImage_view_center:(CGFloat)textImage_view_center {
    if (_textImage_view_center != textImage_view_center) {
        _textImage_view_center =textImage_view_center;
        
        [self updateConstraints_lineView];
    }
}

- (void)updateConstraints_lineView {
    if (_lineView) {
        [_lineView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self.mas_centerX);
            make.centerY.mas_equalTo(self.mas_centerY).offset(self.textImage_view_center);
            make.width.mas_equalTo(self.text_image_space);
            make.height.mas_equalTo(self.text_image_space);
        }];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
